VERSIONS = ["1.2.5", "1.2.6"]
DEFAULT_VERSION = "1.2.5"
OLDER_VERSIONS = ["1.2.5"]

def url( machine, directories, version ):
  """
  http://zlib.net/fossils/zlib-1.2.5.tar.gz
  http://zlib.net/zlib-1.2.6.tar.gz
  """
  URL_STR = "http://zlib.net/%(OLDER)szlib-%(VERSION)s.tar.gz"
  return URL_STR % { "VERSION" : version, "OLDER" : "fossils/" if version in OLDER_VERSIONS else "" }
URL = url

from source.builders import CMakeBuilder
import os, ext.patch

class ZlibBuilder( CMakeBuilder ):

  def configure(self):
    params = "-DBUILD_SHARED_LIBS=" + ( "OFF" if self.runtime.build_linktype == "static" else "ON" )
    super(ZlibBuilder, self).configure( additional_args=params )

  def patch(self):
    os.chdir( self.extractedpath )

    patchstr = """
diff -r 1cd007444504 CMakeLists.txt
--- CMakeLists.txt	Mon Nov 19 15:54:38 2012 +0100
+++ CMakeLists.txt	Mon Nov 19 15:59:16 2012 +0100
@@ -151,7 +151,9 @@
    set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
 elseif(BUILD_SHARED_LIBS AND WIN32)
     # Creates zlib1.dll when building shared library version
-    set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
+
+    STRING( REGEX REPLACE "\\." "" SHORT_VERSION ${ZLIB_FULL_VERSION} )
+    set_target_properties(zlib PROPERTIES SUFFIX "${SHORT_VERSION}.dll")
 endif()
 
 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
"""
    p = ext.patch.fromstring(patchstr)
    print "Patch applied: ", p.apply()

BUILDER = ZlibBuilder
 
